<template>
  <!--违规行为-->
    <search-table
      :columns="listCol" 
      :data="retData.list"
      :total="retData.total"
      :page.sync="queryParams.pageIndex"
      :size.sync="queryParams.pageSize"
      @change-page="getBehaviorList"
      @change-size="getTargetSize"
    >
      <template slot="alert" v-if="false">
        <div class="header_box">
          <div class="display_flex">
            <div class="left_text">处理统计</div>
            <div class="center_text">
              <span>待确认：</span>
              <span class="number_size">{{ behaviorData.notFinishCount }}</span>
            </div>
            <div class="right_text">
              <span>总数：</span>
              <span class="number_size">{{ behaviorData.totalCount }}</span>
              <span>已确认：</span>
              <span class="number_size">{{ behaviorData.finishCount }}</span>
              <span>误报：</span>
              <span class="number_size">{{
                behaviorData.misdeclarationCount
              }}</span>
            </div>
          </div>
        </div>
      </template>
      <template slot="button-group">
        <Button type="primary" ghost @click="addViolation">
          <Icon type="md-add" />
          添加
        </Button>
        <!-- <Button type="primary" ghost @click="addHandle">
          <Icon type="md-add" />
          处理
        </Button>
        <Button type="primary" ghost @click="addHandle">
          <Icon type="md-add" />
          重新处理
        </Button>
        <Button type="primary" ghost @click="addHandleRecords">
          <Icon type="md-add" />
          处理记录
        </Button> -->
        <Button type="primary" ghost @click="threatDetails" v-if="false">
          <Icon type="md-add" />
          <!-- 暂时没有威胁名称，查看不了详情，故隐藏 -->
          威胁详情
        </Button>
      </template>
      <template slot="select-group">
        <Select filterable
          v-model="queryParams.teamId"
          placeholder="请选择团队"
          clearable
          transfer
          @on-change="getBehaviorList(1)"
        >
          <Option
            v-for="item in teamList"
            :value="item.id"
            :key="item.id"
            :title="item.name"
          >{{ item.name }}</Option>
        </Select>
        <!-- 系统一般不指定实验员 -->
        <!-- <Select filterable
          v-model="queryParams.userId"
          placeholder="选择成员"
          filterable
          clearable
          transfer
          @on-change="getBehaviorList(1)"
        >
          <Option value="1">张三</Option>
          <Option value="2">李四</Option>
        </Select> -->
        <Select filterable
          v-model="queryParams.severity"
          placeholder="选择程度"
          clearable
          transfer
          @on-change="getBehaviorList(1)"
        >
          <Option value="slight">轻微</Option>
          <Option value="sameAs">一般</Option>
          <Option value="serious">严重</Option>
          <Option value="extreme">极端</Option>
        </Select>
        <Select filterable
          v-model="queryParams.status"
          placeholder="是否违规"
          clearable
          transfer
          @on-change="getBehaviorList(1)"
        >
          <Option :value="0">误报</Option>
          <Option :value="1">确认违规</Option>
        </Select>
        <!-- <Select filterable
          v-model="queryParams.status"
          placeholder="状态"
          clearable
          @on-change="getBehaviorList(1)"
        >
          <Option value="0">未确认</Option>
          <Option value="1">已确认</Option>
          <Option value="2">误报</Option>
        </Select> -->
        <Input
          v-model.trim="queryParams.behavior"
          placeholder="违规行为"
          clearable
          @on-change="getBehaviorList(1)"
        ></Input>
      </template>
      <!-- <card-list slot="table" :columns="listCol" :data="retData.list"></card-list> -->
    <!-- <Table class="violations" :columns="listCol" :data="retData.list"></Table> -->

    <Modal
      v-model="addViolationModal"
      title="添加违规"
      width="600px"
      :mask-closable="false"
      :loading="addViolationLoading"
      @on-ok="addFormValidate('formValidate')"
      @on-cancel="cancelFormValidate('formValidate')"
    >
      <Form
        ref="formValidate"
        :model="formValidate"
        :rules="ruleValidate"
        :label-width="80"
      >
        <FormItem label="团队" prop="teamId">
          <Select filterable
            v-model="formValidate.teamId"
            placeholder="请选择团队"
            clearable
            label-in-value
            @on-change="changeGroup"
          >
            <Option
              v-for="item in teamList"
              :value="item.id"
              :key="item.id"
              :title="item.name"
            >{{ item.name }}</Option>
          </Select>
        </FormItem>
        <FormItem label="成员" prop="userId">
          <Select filterable
            v-model="formValidate.userId"
            placeholder="选择成员"
            clearable
            @on-change="changeMember"
          >
            <Option
              v-for="(item, index) in groupUsers"
              :value="item.userId"
              :key="item.userId"
              :title="item.userName"
            >
              {{ item.userName }}
            </Option>
            <!-- <Option value="1" >张三</Option>
            <Option value="2">李四</Option> -->
          </Select>
        </FormItem>
        <FormItem label="违规行为" prop="behavior">
          <Input
            v-model.trim="formValidate.behavior"
            placeholder="请输入违规行为"
          ></Input>
        </FormItem>
        <!-- <FormItem label="状态" prop="status" v-if="false">
          <Select filterable
            v-model="formValidate.status"
            placeholder="请选择状态"
            clearable
            transfer
          >
            <Option value="0">未确认</Option>
            <Option value="1">已确认</Option>
            <Option value="2">误报</Option>
          </Select>
        </FormItem> -->
        <FormItem label="严重程度" prop="severity">
          <Select filterable
            v-model="formValidate.severity"
            placeholder="请选择严重程度"
            clearable
            transfer
          >
            <Option value="slight">轻微</Option>
            <Option value="sameAs">一般</Option>
            <Option value="serious">严重</Option>
            <Option value="extreme">极端</Option>
          </Select>
        </FormItem>
        <FormItem label="处置措施" prop="punish">
          <Select filterable placeholder="处置措施" v-model="formValidate.punish">
            <Option value="0">警告</Option>
            <Option value="1">扣分</Option>
            <Option value="2">警告并扣分</Option>
            <Option value="3">取消比赛资格</Option>
          </Select>
        </FormItem>
        <FormItem label="措施说明" prop="description">
          <Input
            v-model.trim="formValidate.description"
            type="textarea"
            :maxlength="200"
            :autosize="{ minRows: 2, maxRows: 5 }"
            placeholder="措施说明-公告内容"
          ></Input>
        </FormItem>
        <FormItem
          label="警告内容"
          prop="punishContent"
          v-if="formValidate.punish == 0 || formValidate.punish == 2"
        >
          <Input
            v-model.trim="formValidate.punishContent"
            type="textarea"
            :maxlength="200"
            :autosize="{ minRows: 2, maxRows: 5 }"
            placeholder="警告内容"
          ></Input>
        </FormItem>
        <FormItem
          label="扣除分数"
          prop="score"
          v-if="formValidate.punish == 1 || formValidate.punish == 2"
        >
          <InputNumber
            v-model.trim="formValidate.score"
            placeholder="分数"
            :min="1"
            style="width: 100px"
          />
          分
        </FormItem>
      </Form>
    </Modal>
    <!-- 处理和重新处理-->
    <Modal
      v-model="reprocessModal"
      title="违规行为处理"
      :loading="reprocessLoading"
      @on-ok="reprocessSub('handleFormValidate')"
      @on-cancel="reprocessCancel('handleFormValidate')"
    >
      <Form
        ref="handleFormValidate"
        :model="handleFormValidate"
        :rules="handleRuleValidate"
        :label-width="80"
      >
        <FormItem label="是否违规" prop="status">
          <RadioGroup v-model="handleFormValidate.status">
            <Radio :label="1">确认违规</Radio>
            <Radio :label="0">误报</Radio>
          </RadioGroup>
        </FormItem>
        <FormItem label="处置措施" prop="punish">
          <Select filterable placeholder="处置措施" v-model="handleFormValidate.punish">
            <Option value="0">警告</Option>
            <Option value="1">扣分</Option>
            <Option value="2">警告并扣分</Option>
            <Option value="3">取消比赛资格</Option>
          </Select>
        </FormItem>
        <FormItem label="措施说明" prop="description">
          <Input
            v-model.trim="handleFormValidate.description"
            type="textarea"
            :maxlength="200"
            :autosize="{ minRows: 2, maxRows: 5 }"
            placeholder="措施说明-公告内容"
          ></Input>
        </FormItem>

        <FormItem
          label="警告内容"
          prop="punishContent"
          v-if="
            handleFormValidate.punish == 0 || handleFormValidate.punish == 2
          "
        >
          <Input
            v-model.trim="handleFormValidate.punishContent"
            type="textarea"
            :maxlength="200"
            :autosize="{ minRows: 2, maxRows: 5 }"
            placeholder="警告内容"
          ></Input>
        </FormItem>
        <FormItem
          label="扣除分数"
          prop="score"
          v-if="
            handleFormValidate.punish == 1 || handleFormValidate.punish == 2
          "
        >
          <InputNumber
            v-model.trim="handleFormValidate.score"
            placeholder="分数"
            :min="1"
            style="width: 100px"
          />
          分
        </FormItem>
      </Form>
    </Modal>
    <!-- 处理记录 -->
    <Modal
      v-model="handleRecordsModal"
      title="违规行为处理记录"
      :mask-closable="false"
      footer-hide
      width="1200"
      @on-cancel="handleRecordCancel"
    >
      <Table
        border
        :columns="handleRecordsCol"
        :data="handleRecordsList"
      ></Table>
      <Page
        class="page_top_center"
        :total="recordTotal"
        :current="recordCurrentPage"
        :page-size="recordPageSize"
        show-total
        show-elevator
        @on-change="recordChangePage"
      >
      </Page>
    </Modal>
    <!-- 威胁名称 -->
    <Modal
      v-model="threatModal"
      title="威胁详情"
      :mask-closable="false"
      footer-hide
      width="1000"
      @on-cancel="threatCancel"
    >
      <!-- <Row>
        <Col
          span="12"
          v-for="(item, index) in labelObj"
          ::key="index"
          class="margin_bottom"
        >
          <span> {{ item }}: </span>
          <span>李四</span>
        </Col>
      </Row> -->
      <div id="threatDetail">
        <p><span class="label">团队</span><span>李四</span></p>
        <p><span class="label">成员</span><span>李四</span></p>
        <p><span class="label">威胁名称</span><span>李四</span></p>
        <p><span class="label">威胁等级</span><span>李四</span></p>
        <p><span class="label">威胁类别</span><span>李四</span></p>
        <p><span class="label">可信度</span><span>李四</span></p>
        <p><span class="label">源ip</span><span>李四</span></p>
        <p><span class="label">源端口</span><span>李四</span></p>
        <p><span class="label">源地区</span><span>李四</span></p>
        <p><span class="label">目的ip</span><span>李四</span></p>
        <p><span class="label">目的端口</span><span>李四</span></p>
        <p><span class="label">目标地区</span><span>李四</span></p>
        <p><span class="label">传输层协议</span><span>李四</span></p>
        <p><span class="label">应用层协议</span><span>李四</span></p>
        <p><span class="label">攻击结果</span><span>李四</span></p>
        <p><span class="label">时间</span><span>李四</span></p>
        <p><span class="label">威胁IOC</span><span>李四</span></p>
        <p><span class="label">详细信息</span><span>李四</span></p>
      </div>
    </Modal>
  </search-table>
</template>
<script>
	import {getaccessgroupmember,getaccessgrouplist} from '@/api/access_new'
// import { allDirection } from '@/api/dict';
import groupMixin from '@/mixin/groupMixin';
// import LevelMixin from '@/mixin/levelMixin';
import SearchTable from '@/components/SearchTable/SearchTable';
import {behavior,behaviorList,addBehavior,addBehaviorDispose,behaviorDisposeList } from '@/api/integration3d';
 import encryption from '@/libs/encryption.js'
export default{
  name: 'violations',
  mixins: [groupMixin],
  data () {
     const d = function(val) {
      this.getBehaviorList(null, null, val);
    }.bind(this);
     const validateNum = (rule, value, callback) => {
      //验证只能填入数字
      var reg = new RegExp('^([1-9]|[1-9]\\d|100)$');
      //验证警戒值
      if (value) {
        if (!reg.test(value)) {
          callback(new Error('请输入1-100的整数'));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    return {
      c: false,
      USER_ID:'',
      USER_Name:'',
      retData: {
        total: 0,
        list: []
      },
      queryParams: {
        teamId: '',
        status:'',
        userId:'',
        severity: '',
        type: '',
        behavior:'',
        pageIndex: 1,
        pageSize: 10
      },
      modalTitle: '',
      topoTargetData: [],
      reportModal: false,
      listCol: [
        {
          title: '团队',
          key: 'teamName',
          align: 'center',
          ellipsis: true,
          tooltip: true,
          minWidth: 100,
        },
         {
          title: '成员',
          key: 'userName',
          align: 'center',
          ellipsis: true,
          tooltip: true,
          minWidth: 100
        },
        {
          title: '违规行为',
          key: 'behavior',
          align: 'center',
          ellipsis: true,
          tooltip: true,
          minWidth: 100
        },
        {
          title: '严重程度',
          key: 'severity',
          align: 'center',
          ellipsis: true,
          tooltip: true,
          minWidth: 100,
           render: (h, params) => {
            let punish = this.severityText(params.row.severity)
            return h('span',punish)
          }
        },
        // {
        //   title: '威胁名称',
        //   key: 'name',
        //   align: 'center',
        //   ellipsis: true,
        //   tooltip: true,
        //   width: 100,
        //    render: (h, params) => {
        //     let name = params.row.name
        //     return h('span',name || '-')
        //   }
        // },
        // {
        //   title: '威胁等级',
        //   key: 'level',
        //   align: 'center',
        //   ellipsis: true,
        //   tooltip: true,
        //   width: 100,
        //    render: (h, params) => {
        //     let level = params.row.level
        //     return h('span',level || '-')
        //   }
        // },
         {
          title: '是否违规',
          key: 'status',
          width: 100,
           tooltip: true,
           render: (h, params) => {
            // let status = params.row.status == 0 ? '待确认' :  params.row.status == 1? '已确认':'误报'
            let status = params.row.status == 0 ? '误报' :  params.row.status == 1? '确认违规':'待确认'
            return h('span',status)
          }
        },
        {
          title: '处置措施',
          key: 'punish',
          align: 'center',
          ellipsis: true,
          tooltip: true,
          width: 100,
           render: (h, params) => {
            let punish = this.punishText(params.row.punish)
            return h('span',punish)
          }
        },
        {
          title: '来源',
          key: 'type',
          align: 'center',
          ellipsis: true,
          tooltip: true,
          minWidth: 100,
          render: (h, params) => {
            let type = params.row.type == 0 ? '手动' : '自动'
            return h('span',type)
          }
        },
        {
          title: '时间',
          key: 'createTime',
          align: 'center',
          ellipsis: true,
          tooltip: true,
          minWidth: 140
        },
        {
          title: '警告内容',
          key: 'punishContent',
          align: 'center',
          ellipsis: true,
          tooltip: true,
          width: 140
        },
        // {
        //   title: '说明',
        //   key: 'description',
        //   align: 'center',
        //   ellipsis: true,
        //   tooltip: true,
        //   width: 100,
        // },
       
        // {
        //   title: '状态', //1提交，2审批通过，3审批不通过
        //   key: 'status',
        //   align: 'center',
        //   ellipsis: true,
        //   tooltip: true,
        //   placement: 'top-right',
        //   render: (h, params) => {
        //     return h(
        //       'span',
        //       params.row.status == 1 ? '提交' : params.row.status == 2 ? '审批通过' : '审批不通过'
        //     );
        //   }
        // },
       
        {
          title: '操作',
          align: 'center',
          // placement: 'top-right',
          fixed:'right',
          key:'action',
          width: 280,
          opList:[
            {
              txt:"流量分析",
              show:(data) => {
                return data.type == 0 ? false : true
              },
              disabled: (data) => {
                return data.type == 0
              },
              fun:this.toPacketAnalysis
            },
            {
              txt:"处理",
              show:(data) => {
                return data.type == 0 ? false : true
              },
              disabled: (data) => {
                return data.type == 0
              },
              fun:(data) => this.addHandle(data,'add')
            },
            {
              txt:"重新处理",
              fun:(data) => this.addHandle(data,'modify')
            },
            {
              txt:'处理记录',
              fun:(data) => this.addHandleRecords(data.id)
            }
          ],
          // render: (h, params) => {
          //   return h(
          //     'div',
          //     {
          //       style: {
          //         width: '260px'
          //       }
          //     },
          //     [
          //       h(
          //         'Button',
          //         {
          //           props: {
          //             type: 'primary',
          //             size: 'small',
          //             disabled: params.row.type == 0
          //           },
          //           style: {
          //             marginRight: '5px',
          //             display: params.row.type == 0 ? 'none' : 'inline-block'
          //           },
          //           on: {
          //             click: () => {
          //               this.toPacketAnalysis(params.row)
          //             }
          //           }
          //         },
          //         '流量分析'
          //       ),
          //       h(
          //         'Button',
          //         {
          //           props: {
          //             type: 'primary',
          //             size: 'small',
          //             disabled: params.row.type == 0
          //           },
          //           style: {
          //             marginRight: '5px',
          //             display: params.row.type == 0 ? 'none' : 'inline-block'
          //           },
          //           on: {
          //             click: () => {
          //               this.addHandle(params.row,'add');
          //             }
          //           }
          //         },
          //         '处理'
          //       ),
          //       h(
          //         'Button',
          //         {
          //           props: {
          //             type: 'primary',
          //             size: 'small',
          //             // disabled: params.row.status !== 1
          //           },
          //           style: {
          //             marginRight: '5px',
          //             // display: params.row.status === 1 ? 'inline-block' : 'none'
          //           },
          //           on: {
          //             click: () => {
          //               this.addHandle(params.row,'modify');
          //             }
          //           }
          //         },
          //         '重新处理'
          //       ),
          //       h(
          //         'Button',
          //         {
          //           props: {
          //             type: 'primary',
          //             size: 'small'
          //           },
          //           style: {
          //             marginRight: '5px',
          //             // display: params.row.status === 1 ? 'inline-block' : 'none'
          //           },
          //           on: {
          //             click: () => {
          //               this.addHandleRecords(params.row.id);
          //             }
          //           }
          //         },
          //         '处理记录'
          //       ),
                
          //     ]
          //   );
          // }
        }
      ],
      reportInitObj: {
        Button: [],
        Input: [],
        Select: [],
        DatePicker: {
          isShow: false,
          fnName: d
        },
        Page: {
          total: 0,
          currentPage: 1,
          pageSize: 10
        },
        listData: []
      },
      timeout: {},
      industryList: [],
      attackList: [],
      extent4InjuryData: [],
      extent4DefenseTypesData: [],
      ruleList: [],
      companyList: [],
      addViolationModal: false,
      addViolationLoading: true,
      formValidate: {
        teamId: '',
        teamName: '',
        userId: '',
        userName: '',
        behavior: '',
        // status: '0',
        score: 0,
        severity: '',
        punish: '',
        description: '',
        punishContent: '',
        type: 0,
        sceneId: this.$route.query.id
      },
      ruleValidate: {
        teamId: [
          { required: true, message: '请选择团队', trigger: 'change' }
        ],
        userId: [
          { required: false, message: '请选择成员', trigger: 'change' },
        ],
        status: [
          { required: true, message: '请选择状态', trigger: 'change' },
        ],
        behavior: [
          { required: true, message: "请输入违规行为",trigger: 'change' }
        ],
        severity: [
          { required: true, message: '请选择严重程度', trigger: 'change' }
        ],
        punish: [
          { required: true, message: '请选择处置措施', trigger: 'change' }
        ],
        punishContent: [
          { required: true, message: '请输入警告内容', trigger: 'blur' }
        ],
        description: [
          { required: true, message: '请输入措施说明', trigger: 'blur' }
        ],
        score: [
          { required: true,type:'number', message: '输入分数', trigger: 'change'},
          // { required: true,type:'number',min:1, max:100, message: '请输入1-100的整数', trigger: 'change' },
          { trigger: 'change',validator: validateNum  }
        ],
      },

      // 处理
      reprocessModal: false,
      reprocessLoading: true,
      handleFormValidate: {
        status: 0,
        score:0,
        punish:'0',
        description:'',
        punishContent: '',
        sceneId: this.$route.query.id,
        id: '',
        userId:'',
        userName:'',
      },
      handleRuleValidate: {
          status: [
          { required: true,type: 'number',message: "请选择违规",trigger: 'change' }
        ],
        description: [
          { required: true, message: '请输入措施说明', trigger: 'change' }
        ],
        punish: [
          { required: true, message: '请选择处置措施', trigger: 'change' }
        ],
        punishContent: [
          { required: true, message: '请输入警告内容', trigger: 'change' }
        ],
         score: [
          { required: true,type:'number', message: '输入分数', trigger: 'change'},
          // { required: true,type:'number',min:1, max:100, message: '请输入1-100的整数', trigger: 'change' },
          { trigger: 'change',validator: validateNum  }
        ],
      },

      // 记录
      handleRecordsModal:false,
      recordCurrentPage:1,
      recordPageSize:10,
      recordTotal:0,
      // handleRecordsLoading: true,
      handleRecordsCol: [
        {
          type: 'index',
          width: 60,
          align: 'center'
        },
         {
          title: '核实结果',
          key: 'status',
          align: 'center',
          ellipsis: true,
           tooltip: true,
            render: (h, params) => {
            let status = this.statusText(params.row.status)
            return h('span',status)
          }
         
        },
         {
          title: '处置措施',
          key: 'punish',
          align: 'center',
          ellipsis: true,
           tooltip: true,
           render: (h, params) => {
            let punish = this.punishText(params.row.punish)
            return h('span',punish)
          }
        },
         {
          title: '操作人',
          key: 'creatorName',
          align: 'center',
          ellipsis: true,
          tooltip: true
        },
         {
          title: '操作时间',
          key: 'checkTime',
          align: 'center',
          ellipsis: true,
          tooltip: true
        },
         {
          title: '说明',
          key: 'description',
          align: 'center',
          ellipsis: true,
          tooltip: true
        },
         {
          title: '告警内容',
          key: 'punishContent',
          align: 'center',
          ellipsis: true,
          tooltip: true
        },
      ],
      handleRecordsList: [],

      // 威胁闲情
      threatModal: false,
      threaParams:{},
      labelObj: {
        name1:'团队',
        name2:'成员',
        name3:'威胁名称',
        name4:'威胁等级',
        name5:'威胁类别',
        name6:'可信度',
        name7:'源ip',
        name8:'目的ip',
        name9:'源端口',
        name10:'目的端口',
        name11:'传输层协议',
        name12:'应用层协议',
        name13:'源地区',
        name14:'目标地区',
        name15:'攻击结果',
        name16:'时间',
        name17:'威胁IOC',
        name18:'详细信息',
      },
      sceneId:this.$route.query.id, // 场景id
      projectId: this.$route.query.prjid, // 工程id
      // 统计信息
      behaviorData: {
        finishCount:0,
        misdeclarationCount:0,
        notFinishCount:0,
        totalCount:0,
      },
      // 成员
      groupUsers:[],
      teamList: [],
      addDispose:'add',
    };
  },
  computed: {
    filterTeamList() {
      return this.teamList.filter((item) => item.name !== '目标方管理员组');
    }
  },
  components: {
    // 'table-body': tableBody,
    SearchTable
  },
  watch: {},
  created () {
    let September = sessionStorage.getItem('November')
    September = JSON.parse(encryption.SelfUseDecrypt(September));
    this.USER_ID = September.userId
    this.USER_Name = September.nickname
  },
  beforeDestroy() {
    clearTimeout(this.timeout);
  },
  async mounted () {
    this.getBehavior()
    this.getaccessgrouplist()
    this.getBehaviorList()
  },
  methods: {
    getTargetSize(val) {
      this.queryParams.pageSize = val
      this.getBehaviorList(1)
    },
    // 违规行为统计
    getBehavior () {
      behavior(this.sceneId).then(res => {
        if (res.code == 1) {
          console.log('=========', res.data);
          this.behaviorData = res.data
        } else {
          this.behaviorData = {
            finishCount: 0,
            misdeclarationCount: 0,
            notFinishCount: 0,
            totalCount: 0,
          }
          this.$Message.warning(res.message)
        }
      }).catch(error => {
        this.$Message.error(error)
      })
    },

    // 违规列表查询
    getBehaviorList (val) {
      if (val) {
        this.queryParams.pageIndex = val
      }
      let params = {
        teamId: this.queryParams.teamId,
        severity: this.queryParams.severity,
        status: this.queryParams.status,
        behavior: this.queryParams.behavior,
        pageIndex: this.queryParams.pageIndex,
        pageSize: this.queryParams.pageSize,
        sceneId:this.sceneId,
      }
      if (!params.teamId) {
        delete params.teamId
      }
      // if (params.status == '') {
      //   delete params.status
      // }
      if (!params.behavior) {
        delete params.behavior
      }
      if (!params.severity) {
        delete params.severity
      }
       behaviorList(this.sceneId,params).then(res => {
        if (res.code == 1) {
          this.retData.list = res.data.items
          this.retData.total = res.data.total
         } else {
          this.retData.list = []
          this.retData.total = 0
          this.$Message.warning(res.message)
        }
      }).catch(error => {
        this.$Message.error(error)
      })
    },

    changeGroup (val) {
      if (!val) return
      this.formValidate.teamId = val.value
      this.formValidate.teamName = val.label
      this.getaccessgroupmember(val.value)
    },
    // 查询接入用户组
    getaccessgrouplist () {
      getaccessgrouplist({
        pageIndex: 1,
        pageSize: 2147483646,
        testId: this.$route.query.id
      }).then(({ code, message, data = {} }) => {
        if (code !== 1) {
          this.$Message.warning(message)
          return
        }
        this.teamList = data.items || []
      })
    },

    //获取接入用户组下的团队成员
    getaccessgroupmember (teamId) {
        getaccessgroupmember(teamId).then(res => {
          console.log(' ~ res:', res)
          if (res.code == 1) {
            this.groupUsers = res.data;
          } else {
            this.$Message.error('获取团队成员失败！');
          }
        }).catch(error => {
          this.$Message.error('获取团队成员失败！');
        })
    },
    changeMember (val) {
      console.log('changeMember ~ val:', val)
      this.formValidate.userId = val
    },

    // 添加违规行为
    addBehavior (name) {
      // let params = {
      //   behavior:this.formValidate.behavior,
      //   severity:this.formValidate.severity,
      //   punish:this.formValidate.punish,
      //   description:this.formValidate.description,
      // }
      addBehavior(this.formValidate).then(res => {
        if (res.code == 1) {
          this.$Message.success(res.message)
          this.$refs[name].resetFields();
          this.colseLoading('addViolationLoading')
          this.getBehaviorList()
          this.addViolationModal = false
        } else {
          this.$Message.warning(res.message)
        }
      }).catch(error => {
        this.$Message.error(error)
      })
    },

    // 添加违规行为
    addViolation () {
      this.addViolationModal = true
    },

    cancelFormValidate (name) {
      this.$refs[name].resetFields();
      this.addViolationModal = false
    },

    addFormValidate (name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.addBehavior(name)
          // this.$Message.success('提交成功!');
          //  this.$refs[name].resetFields();
          // this.colseLoading('addViolationLoading')
          // this.addViolationModal = false
        } else {
          this.$Message.error('表单验证失败!');
          this.colseLoading('addViolationLoading')
        }
      })
    },

    // 处理 重新处理
    addHandle (row, type) {
      console.log('🚀 ~ file: violations.vue:1050 ~ addHandle ~ row:', row)
      if (type == 'add') {
        this.addDispose = 'add'
      } else {
        this.addDispose = 'modify'
      }
      // this.handleFormValidate.id = row.id
      // this.handleFormValidate.punishContent = row.punishContent
      // this.handleFormValidate.description = row.description
      // this.handleFormValidate.punish = row.punish
      // this.handleFormValidate.userId = this.USER_ID
      // this.handleFormValidate.userName = this.USER_Name
      this.handleFormValidate = row
      this.reprocessModal = true
    },

    addBehaviorDispose (name) {
      addBehaviorDispose(this.handleFormValidate.id,this.handleFormValidate).then(res => {
        if (res.code == 1) {
          this.$Message.success(res.message)
          this.$refs[name].resetFields();
          this.getBehaviorList()
          this.colseLoading('reprocessLoading')
          this.reprocessModal = false
        } else {
          this.$Message.warning(res.message)
        }
        
      }).catch(error => {
        this.$Message.error(error)
      })
    },
    reprocessCancel (name) {
      this.$refs[name].resetFields();
      this.reprocessModal = false
    },
    // 处理 重新处理
    reprocessSub (name) {
      this.$refs[name].validate(valid => {
        if (valid) {
          // this.$Message.success('提交成功!');
          // if (this.addDispose == 'add') { }
          this.addBehaviorDispose(name)
        } else {
          this.$Message.error('表单验证失败!');
          this.colseLoading('reprocessLoading')
        }
      })
    },
     // 记录
    addHandleRecords (id) {
      this.handleRecordsModal = true
       this.behaviorDisposeList(id)
    },

    handleRecordCancel () {
      console.log('==关闭');
    },
    recordChangePage (val) {
      console.log('🚀 recordChangePage ~ val:', val)
      this.recordCurrentPage = val
      this.behaviorDisposeList()
    },

        // 处理记录
    behaviorDisposeList (id) {
      let params = {
        punish: '',
        pageIndex:this.recordCurrentPage,
        pageSize:this.recordPageSize,
      }
      behaviorDisposeList(id,params).then(res => { 
        if (res.code == 1) {
          console.log('res', res.data);
          this.handleRecordsList = res.data.items
          this.recordTotal = res.data.total
        } else {
          
          this.$Message.warning(res.message)
        }
      }).catch(error => {
        this.$Message.error(error)
      })
    },



    // 威胁详情
    threatDetails () {
      this.threatModal = true
    },
    threatCancel () {
      this.threaParams = {}
      this.threatModal = true
    },


    // 统一为modal 的 loading 设置 
    colseLoading (name) {
      // name 为关闭的loading 变量
      this[name] = false
      this.$nextTick(() => {
        this[name] = true;
      });
    },

    punishText (val) {
      let str = ''
      switch (val) {
        case "0": str = '警告'; break;
        case "1": str = '扣分'; break;
        case "2": str = '警告并扣分'; break;
        case "3": str = '取消比赛资格'; break;
         default: str = '-'; break;
      }
      return str;
    },
    severityText (val) {
      let str = ''
      switch (val) {
        case "slight": str = '轻微'; break;
        case "sameAs": str = '一般'; break;
        case "serious": str = '严重'; break;
        case "extreme": str = '极端'; break;
        default: str = '-'; break;
      }
      return str;
    },
    statusText (val) {
      let str = ''
      switch (val) {
        case 1: str = '确认违规'; break;
        case 0: str = '误报'; break;
      }
      return str;
    },

    // 流量分析
    toPacketAnalysis (row) {
       this.$router.push({
        name: 'packetAnalysis',
        query: {
          sceneName: row.name || '护网数据包',
          sceneId: row.sceneId || '123',
          projectId: row.projectId || '456',
          name: this.$route.query.name,
          prjid: this.$route.query.prjid,
          id: this.$route.query.id,
          page: this.$route.query.page
        }
      });
    },

  }
};
</script>

<style>
#violations .ivu-table-overflowX {
  overflow-x: auto;
}
</style>
<style scoped>
/* .sceneDetail .ivu-table-overflowX {
    overflow-x: unset !important;
} */
.margin_bottom {
  margin-bottom: 10px;
  /* font-size: 15px; */
}
.margin_bottom span:first-child {
  width: 85px;
  display: inline-block;
  text-align-last: justify;
  padding-left: 5px;
}
#threatDetail {
  display: table;
  width: 100%;
  border: 1px solid #eee;
  table-layout: fixed;
  word-break: break-all;
}
#threatDetail p {
  display: table-row;
  line-height: 36px;
  text-align: center;
}
#threatDetail p span {
  display: table-cell;
  border-bottom: 1px solid #eee;
}

.Titles {
  background: #eeeeee;
  margin: 16px auto;
  padding: 10px 0;
}
.targetHeader {
  padding: 10px;
  margin-bottom: 10px;
}
.header_box {
  height: 100px;
  width: 100%;
  border: 1px solid #999;
  border-radius: 4px;
  box-shadow: 0px 0px 4px #999;
}
.display_flex {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: space-around;
  align-items: center;
  line-height: 100px;
}
.left_text {
  width: 20%;
  font-size: 20px;
}
.center_text {
  width: 30%;
  font-size: 15px;
}
.right_text {
  font-size: 15px;
}
.right_text .number_size {
  font-size: 20px;
  margin-right: 20px;
}
.center_text .number_size {
  font-size: 20px;
}
.page_top_center {
  margin-top: 15px;
  text-align: center;
}

.page_top_center /deep/ .ivu-page-item-active {
  border-color: #1563C2 ;
  box-shadow: none;
  outline: none;
}
.page_top_center /deep/ .ivu-page-item:hover,
.page_top_center /deep/ .ivu-page-next:hover,
.page_top_center /deep/ .ivu-page-prev:hover {
  border-color: #1563C2 ;
}
.page_top_center /deep/ .ivu-page-item:hover a,
.page_top_center /deep/ .ivu-page-next:hover a,
.page_top_center /deep/ .ivu-page-prev:hover a,
.page_top_center /deep/ .ivu-page-item-jump-prev:hover a,
.page_top_center /deep/ .ivu-page-item-jump-next:hover a {
  color: #1563C2 ;
}
.page_top_center /deep/ .ivu-page-item-active a {
  color: #1563C2  !important;
}
.page_top_center /deep/ .ivu-page-options-elevator input:focus {
  border-color: #1563C2 ;
  box-shadow: 0px 0px 8px #1563C2 ;
}
.page_top_center /deep/ .ivu-page-options-elevator input:hover {
  color: #1563C2  !important;
  border-color: #1563C2 ;
  box-shadow: 0px 0px 8px #1563C2 ;
}
.page_top_center >>> .ivu-page-options-elevator input {
  height: 28px;
  border-color: #5f5f5f;
}
</style>
